package net.xdclass.controller;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import net.xdclass.request.LockProductRequest;
import net.xdclass.service.ProductService;
import net.xdclass.util.JsonData;
import net.xdclass.vo.ProductVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 孙浩
 * @since 2022-04-24
 */
@Api(tags = "商品服务")
@RestController
@RequestMapping("/api/product/v1")
public class ProductController {

   @Autowired
   private ProductService productService;

  /**
   * 查询商品分页列表
   * @param page
   * @param size
   * @return
   */
   @ApiOperation(value = "查询商品分页列表")
   @GetMapping("/page")
   public JsonData page(@ApiParam(value = "当前页",defaultValue = "1")
                           @RequestParam(value = "page",defaultValue = "1") Integer page,
                        @ApiParam(value = "当前页条数",defaultValue = "3")
                           @RequestParam(value = "size",defaultValue = "3") Integer size){
     return JsonData.buildSuccess(productService.page(page,size));
   }


  /**
   * 查询商品详情
   */
   @ApiOperation(value = "查询商品详情")
   @GetMapping("/detail/{product_id}")
   public JsonData detail(@ApiParam(value = "商品Id")@PathVariable(value = "product_id") String productId){
     return JsonData.buildSuccess(productService.detail(productId));
   }

  /**
   * 商品库存锁定
   */
  @PostMapping("/lock_products")
  public JsonData lockProducts(@RequestBody LockProductRequest lockProductRequest){
    productService.lockProducts(lockProductRequest);
    return JsonData.buildSuccess();
  }


}

